'''
Created on Nov 20, 2011

@author: poco153
'''
import sqlite3

class dbInterface:    
    mConnection = 0
    mCursor = 0
    mFileName = ''
    mTableName = ''
    i = 0
    def __init__(self, fileName, tableName, tableParams):
        dbInterface.mConnection = sqlite3.connect(fileName)
        dbInterface.mCursor = dbInterface.mConnection.cursor()
        
        try: #If the table we want does not exist, create it...
            #db creation...
            cmd = "CREATE TABLE {0} ({1})".format(tableName, tableParams)
            dbInterface.mCursor.execute(cmd)
            dbInterface.mConnection.commit()
        except Exception:
            print "Table Already Exists!"
            pass
    
    def addNewRow(self, date, jobNum, jobDesc, hours):
        dbInterface.mCursor.execute("INSERT INTO testTable VALUES(?, ?, ?, ?, ?)", (dbInterface.i, date, jobNum, jobDesc, hours))
        dbInterface.i += 1
        
    def readAll(self):
        dbInterface.mCursor.execute('SELECT * FROM testTable')
        all = dbInterface.mCursor.fetchall()
        
        for row in all:
            print row

